var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(t, e) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(t, e) {
        t.__proto__ = e;
    } || function(t, e) {
        for (var i in e) e.hasOwnProperty(i) && (t[i] = e[i]);
    })(t, e);
}, function(t, e) {
    function i() {
        this.constructor = t;
    }
    o(t, e), t.prototype = null === e ? Object.create(e) : (i.prototype = e.prototype, 
    new i());
}), a = this && this.__decorate || function(t, e, i, o) {
    var n, s = arguments.length, a = s < 3 ? e : null === o ? o = Object.getOwnPropertyDescriptor(e, i) : o;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) a = Reflect.decorate(t, e, i, o); else for (var r = t.length - 1; 0 <= r; r--) (n = t[r]) && (a = (s < 3 ? n(a) : 3 < s ? n(e, i, a) : n(e, i)) || a);
    return 3 < s && a && Object.defineProperty(e, i, a), a;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("AudioManager"), s = e("GameManager"), c = e("EditView"), l = e("GameBlockChristmas"), d = cc._decorator, u = d.ccclass, p = d.property, h = function(e) {
    function t() {
        var t = null !== e && e.apply(this, arguments) || this;
        return t.skeleton = null, t.shadow = null, t.gameView = null, t.moveDir = cc.v2(), 
        t._moveSpeed = 300, t.moveTime = 0, t.giftTime = 0, t.originScale = .5, t;
    }
    return i(t, e), t.prototype.onLoad = function() {
        this.gameView = s.default.getInstance().gameView, this.originScale = this.skeleton.node.scale, 
        this.shadow.parent = this.gameView.bottom;
    }, t.prototype.doMove = function(t) {
        this.moveTime + 1e3 < Date.now() && (this.moveTime = Date.now(), this.moveDir = cc.v2(Math.random() - .5, Math.random() - .5).normalizeSelf(), 
        this.updateDir(this.moveDir)), this.move(t);
    }, t.prototype.doGift = function() {
        var e, i = this;
        this.giftTime + 8e3 < Date.now() && (e = this.gameView.astar.getGird(this.node.getPosition()), 
        0 == this.gameView.astar.gridsList[e.x][e.y].type && this.gameView.targets.every(function(t) {
            return !i.gameView.astar.getGird(t.node.getPosition()).equals(e);
        }) && (r.default.getInstance().playAudio("圣诞老人扔礼物"), this.addBox(e), this.giftTime = Date.now()));
    }, t.prototype.move = function() {
        var t = this.moveDir.mul(this._moveSpeed / 60), t = this.node.getPosition().add(t);
        t.equals(this.node.getPosition()) || this.node.setPosition(this.check(t));
    }, t.prototype.check = function(t) {
        var e = Math.abs((this.node.width - this.gameView.map.width) / 2), i = Math.abs((this.node.height - this.gameView.map.height) / 2);
        return t.x > e ? t.x = e : t.x < -e && (t.x = -e), t.y > i ? t.y = i : t.y < -i && (t.y = -i), 
        t;
    }, t.prototype.update = function(t) {
        this.doMove(t), this.doGift(t), this.shadow && this.shadow.active && this.shadow.setPosition(this.node.getPosition());
    }, t.prototype.updateDir = function(t) {
        void 0 === t && (t = this.moveDir), this.skeleton && (0 < t.x ? this.skeleton.node.scaleX = -this.originScale : t.x < 0 && (this.skeleton.node.scaleX = this.originScale));
    }, t.prototype.addBox = function(t) {
        var e = new cc.Node(), i = e.addComponent(l.default);
        i && (e.parent = this.gameView.layout, i.gird = t, e.setContentSize(80, 80), e.zIndex = 2 * -t.y, 
        e.setPosition(cc.v2(80 * i.gird.x + 40 - this.gameView.map.width / 2, 80 * i.gird.y + 40 - this.gameView.map.height / 2)), 
        i.type = c.BlockType.BOX, i.init("texture/map/christmas/gift_" + GA.rand(0, 2)), 
        i.addShadow(), this.gameView.blocks.push(i), this.gameView.astar.gridsList[t.x][t.y].type = -1, 
        this.gameView.astar.gridsList[t.x][t.y].target = i);
    }, a([ p(sp.Skeleton) ], t.prototype, "skeleton", void 0), a([ p(cc.Node) ], t.prototype, "shadow", void 0), 
    a([ u ], t);
}(cc.Component);

n.default = h;